#include "appender.h"

namespace Log4Qt
{

Appender::Appender(const QString &name,
                   const QString &charset,
                   const QSharedPointer<Layout> &layout)
{
    this->name = name;
    this->charset = charset;
    this->layout = layout;
    codec = QTextCodec::codecForName(charset.toStdString().c_str());
}

ConsoleAppender::ConsoleAppender(const QString &name,
                                 const QString &charset,
                                 const QSharedPointer<Layout> &layout)
    : Appender(name, charset, layout)
{
}

void ConsoleAppender::append(const QString &loggerName,
                        const char *fileName,
                        int fileLine,
                        const QString &level,
                        const QString &msg)
{
    QString formatted = layout->format(loggerName, fileName, fileLine, level, msg);
    QByteArray buffer = codec->fromUnicode(formatted);
    std::clog << buffer.constData() << std::endl;
}

}
